package com.yuchen.ishop.service.buyer;

import com.yuchen.ishop.entity.Comment;
import com.yuchen.jaxrs.Responses;
import com.yuchen.jaxrs.restclient.RestClientUtils;
import com.yuchen.utils.config.ConfigUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.ws.rs.core.GenericType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 */
@Service
public class BuyerCommentRestClient {

    private final static Logger LOG = Logger.getLogger(BuyerCommentRestClient.class);

    public Comment getById(Long id) {
        String url = ConfigUtils.config.get("buyerComment_getById");
        Map map = new HashMap(1);
        map.put("id", id);
        url = RestClientUtils.url(url, map);
        return RestClientUtils.get(Comment.class, url);
    }

    public Responses insert(Comment Comment) {
        String url = ConfigUtils.config.get("buyerComment_insert");
        return RestClientUtils.post(Responses.class, Comment, url);
    }

    public Responses update(Comment Comment) {
        String url = ConfigUtils.config.get("buyerComment_update");
        return RestClientUtils.post(Responses.class, Comment, url);
    }

    public Responses delete(Long id) {
        String url = ConfigUtils.config.get("buyerComment_delete");
        Map map = new HashMap(1);
        map.put("id", id);
        url = RestClientUtils.url(url, map);
        return RestClientUtils.delete(Responses.class, url);
    }

    public List<Map> getByBuyerId(Long buyerId, String range){
        String url = ConfigUtils.config.get("buyerComment_getByBuyerId");
        Map params = new HashMap(1);
        params.put("buyerId",buyerId);
        params.put("range",range);
        url =  RestClientUtils.url(url, params);
        GenericType genericType =  new GenericType<List<Map>>() {};
        List<Map> json = RestClientUtils.get(genericType,url);
        return json;
    }
}